<?php

class ExamCenterController extends Controller {

    public function actionIndex() {
        #$this->render('index');
        $this->actionListCenterRegion(-1);
    }

    /*
     * 功能：输出制定地点周围的体检中心
     * 参数：uid-用户id，lat-当前的维度, lon-当前的经度，radius-查找范围(单位是米)
     * 返回：范围内体检中心信息列表的json串
     */

    public function actionLbsSearch() {
        if(!isset($_GET["gps_lat"])||!isset($_GET["gps_lon"])){
            JSONHelper::echoJSON(false,  JSONHelper::ERROR_ILLEGAL_REQUEST);
        }
        $radio = isset($_GET["radio"])?$_GET["radio"]:CenterServices::DEFAULT_SEARCH_RADIUS;
        $s = new CenterServices();
        $ret = $s->getCenterListByLatAndLon($_GET["gps_lat"], $_GET["gps_lon"],$radio);
        JSONHelper::echoJSON(true,$ret);
    }

    /*
     * list the the prov_city list of all the physical exam centers
     * @return json string of list of all the physical exam centers
     */

    public function actionListcenterregion() {
        $center = new CenterServices();
        $result = $center->getCenterRegion();
        if (is_int($result)) {
            JSONHelper::echoJSON(false, $result);
        }
        echo JSONHelper::retInfo(true, $result);
    }

    /*
     * @params： province-省名，city--市名。编码为utf8
     * @return 返回给定省市的所有体检中心列表
     */

    public function actionGetcentersbycity() {
        $center = new CenterServices();
        $result = $center->getCentersByCity($_GET);
        if (is_int($result)) {
            JSONHelper::echoJSON(false, $result);
        }
        JSONHelper::echoJSON(true, $result);
    }
    /*
     * @return 按照条件返回给定省市的所有体检中心列表，并按省市体检品牌归类
     */

    public function actionGetCentersOrderByCity() {
        $center = new CenterServices();
        $result = $center->getCentersOrderByCity($_GET);
        if (is_int($result)) {
            JSONHelper::echoJSON(false, $result);
        }
        JSONHelper::echoJSON(true, $result);
    }
    /**
     * @return 返回体检品牌列表
     */
    public function actionGetBrands()
    {
        $center = new CenterServices();
        
        $result = $center->getBrands();
        if (is_int($result)) {
            JSONHelper::echoJSON(false, $result);
        }
        JSONHelper::echoJSON(true, $result);
    }
	/**
	 * 获取体检中心详情
	 */
	public function actionGetCenterDetails()
	{
		if(!isset($_GET["cid"]))
		{
			JSONHelper::echoJSON(false, JSONHelper::ERROR_ILLEGAL_REQUEST);
		}
		$center = new CenterServices();
        
        $result = $center->getCenterDetails($_GET["cid"]);
        if (is_int($result)) {
            JSONHelper::echoJSON(false, $result);
        }
        JSONHelper::echoJSON(true, $result);
	}

    
}
